package written.test;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 0; i < n; i++){
            int len = sc.nextInt();
            int[] arr = new int[len];
            for(int j = 0; j < len; j++){
                arr[j] = sc.nextInt();
            }
            System.out.println(judge(arr)?"Y":"N");
        }
    }
    public static boolean judge(int[] arr){
        int k = 0;
        for(int i = 1; i < arr.length; i++){
            if(arr[i] > arr[i-1]) {
                k++;
            }
        }
        if(k>1) return false;
        else if(k==0) return true;
        return arr[0] <= arr[arr.length-1];
    }
}
